/* $Id: DatabaseTreeCellRenderer.java 56 2010-01-23 14:49:04Z aaron.day $ */
package org.crazydays.gameplan.db.swing;


import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.crazydays.gameplan.util.IconHelper;
import org.crazydays.i18n.Messages;

/**
 * DatabaseTreeCellRenderer
 */
public class DatabaseTreeCellRenderer
    extends DefaultTreeCellRenderer
{
    /** serial version uid */
    public final static long serialVersionUID =
        "$Id: DatabaseTreeCellRenderer.java 56 2010-01-23 14:49:04Z aaron.day $"
            .hashCode();

    /** messages */
    public final static Messages messages = Messages.getInstance();

    /**
     * @param tree
     * @param value
     * @param selected
     * @param expanded
     * @param leaf
     * @param row
     * @param hasFocus
     * @return
     * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree,
     *      java.lang.Object, boolean, boolean, boolean, int, boolean)
     */
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row,
        boolean hasFocus)
    {
        Icon icon = null;

        if (value instanceof DatabaseNode) {
            icon =
                IconHelper.loadIcon(messages
                    .getMessage("view.databaseTree.database.icon"));
        } else if (value instanceof MapsNode) {
            icon =
                IconHelper.loadIcon(messages
                    .getMessage("view.databaseTree.maps.icon"));
        } else {
            icon = null;
        }

        this.closedIcon = icon;
        this.leafIcon = icon;
        this.openIcon = icon;

        return super.getTreeCellRendererComponent(tree, value, selected,
            expanded, leaf, row, hasFocus);
    }
}
